# $< stand for the first file of prerequirefiles
# $@ stand for the target files
# $^ stand for all of the prerequirefiles
# %.o:%.cpp stand for the files which replace the %.o's suffix with .cpp
# use -gstabs+ or -gdwarf-2 to get more debug info ??
CC := g++
BINDIR := ../../Bin
LIBDIR := ../../Libs
OBJDIR := ../../Objs
CPPFLAGS :=  -O0  -Wall -fPIC -g -I/usr/local/Cellar/boost/1.46.0/include
LDFLAGS := 
TARGET := libjsonspirit.a
SHARED_TARGET := $(BINDIR)/libjsonspirit.so
SOURCESFILE := $(wildcard *.cpp)
OBJS := $(SOURCESFILE:%.cpp=$(OBJDIR)/%.o)
TARGETPATH := $(LIBDIR)/$(TARGET)

all: $(TARGETPATH) 

shared: $(SHARED_TARGET)
$(TARGETPATH): $(OBJS) 
	$(AR) rcs  $@ $^ 

$(SHARED_TARGET) : $(OBJS)
	$(CC) -shared -o $@ $^
$(OBJDIR)/%.o:%.cpp %.d
	$(CC) -c $(CPPFLAGS) $< -o $@

include $(SOURCESFILE:.cpp=.d)

%.d: %.cpp
	set -e;rm -f $@; $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$

clean:
	-rm -f *.d  $(TARGETPATH) $(OBJS) $(SHARED_TARGET)



